package com.limox.bishe.util;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceActivity;
import android.view.WindowManager;

public class Util {
	private static int viewWidthInPix = -1;
	private static int viewHeightInPix = -1;
	public static int getViewWidthInPix(Context context) {
		if(viewWidthInPix == -1 ) {
			WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
			viewWidthInPix = manager.getDefaultDisplay().getWidth();
		}
		return viewWidthInPix;
	}
	public static int getViewHeightInPix(Context context) {
		if(viewHeightInPix == -1 ) {
			WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
			viewHeightInPix = manager.getDefaultDisplay().getHeight();
		}
		return viewHeightInPix;
	}
	
	
	/**
	 * 读取配置
	 * 
	 * @param context
	 * @param xmlName
	 *            保存文件名
	 * @param key
	 *            字段
	 * @return
	 */
	public static String ReadSharedPerference(Context context, String xmlName,
			String key) {
		SharedPreferences preferences = context.getSharedPreferences(xmlName,
				PreferenceActivity.MODE_PRIVATE);
		// 得到文件中的name标签值，第二个参数表示如果没有这个标签的话，返回的默认值
		String value = preferences.getString(key, "null");
		// 提示用户读取成功
		return value;

	}

	/**
	 * 保存配置
	 * 
	 * @param context
	 * @param xmlName
	 *            保存文件名
	 * @param key
	 *            字段
	 * @param value
	 *            值
	 */
	public static void SharedPerferencesCreat(Context context, String xmlName,
			String key, String value) {
		SharedPreferences preferences = context.getSharedPreferences(xmlName,
				PreferenceActivity.MODE_WORLD_READABLE);
		Editor edit = preferences.edit();
		edit.putString(key, value);
		edit.commit();

	}
	
	
	/**
	 * 跳转到下一个Activity
	 * @param context 
	 * @param Nextclass
	 */
	public static void GoIntent(Context context,Class<?> Nextclass){
		//跳转到课表界面
		Intent goIntent =new Intent();
		goIntent.setClass(context,Nextclass); 
		context.startActivity(goIntent);
		 
	}

	
	
}
